# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=vector
pkgver=0.39.0
pkgrel=0
pkgdesc="High-performance observability data pipeline"
url="https://vector.dev/"
# s390x, ppc64le, loongarch64: blocked by cargo-nextest
# 32-bit: memory allocation error
arch="all !s390x !ppc64le !x86 !armhf !armv7 !loongarch64"
license="MPL-2.0"
makedepends="
	cargo
	cargo-auditable
	cmake
	librdkafka-dev
	openssl-dev
	perl
	protobuf-dev
	protoc
	python3
	zlib-ng-dev
	zstd-dev
	"
checkdepends="bash cargo-nextest tzdata"
subpackages="$pkgname-doc $pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/vectordotdev/vector/archive/refs/tags/v$pkgver.tar.gz
	use-system-libs.patch
	skip-failed-tests.patch
	vector.initd
	vector.confd
	logrotate
	"

export OPENSSL_NO_VENDOR=1

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided zlib-ng
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		z-ng = { rustc-link-lib = ["z-ng"], rustc-cfg = ["zng"] }
	EOF

	# "cargo auditable build" still tries to pull dependencies for other platforms
	cargo fetch --locked
}

build() {
	cargo auditable build \
		--release \
		--frozen \
		--no-default-features \
		--features default-musl,component-validation-runner

	# cargo-nextest drops the release build, so back it up here
	cp -r target/release releasebuild
}

check() {
	# Upstream recommends running tests with "cargo nextest" instead of "cargo test"
	cargo nextest run \
		--fail-fast \
		--frozen \
		--no-default-features \
		--offline \
		--release \
		--workspace \
		--test-threads num-cpus
}

package() {
	install -Dm755 releasebuild/vector -t "$pkgdir"/usr/bin/
	install -Dm644 config/vector.yaml -t "$pkgdir"/etc/vector/
	install -Dm644 "$srcdir"/logrotate "$pkgdir"/etc/logrotate.d/vector

	mkdir -p "$pkgdir"/usr/share/doc/vector
	cp -r config/examples "$pkgdir"/usr/share/doc/vector/examples

	install -Dm755 "$srcdir"/vector.initd "$pkgdir"/etc/init.d/vector
	install -Dm644 "$srcdir"/vector.confd "$pkgdir"/etc/conf.d/vector
}

sha512sums="
88e07414983c530884c00473a6c980e6992f4ffe188d4473f12a4174abb669eb2bedd16af0384f3ac73478134fc2c1956d5d8a2608b8fc0fd0adc1d3bf020a97  vector-0.39.0.tar.gz
4fbd97300ee5d9671acb2498e62f852d474a005d6e993c4ba185c50eb5a80ab494d6a4103a281759a7fbce35ad2a8a42221cdd2e366d5e7cfb0c202bc90ea9ac  use-system-libs.patch
3e0d61d64411ce679241effccbe858ff2c68b20e96d8f9f12089671d8dcc84b0583f6db7512be90b716e3655e18d8a47e1359f4013444f448ec12f0de12f9c25  skip-failed-tests.patch
806c2594d9d7b4bf1c24436a3982801a37ec3d8784acb97266eb7111fe35d8d05a64ef981100bd8aa35a71ad9c7c98de634428f696bded31993143ca572b6757  vector.initd
313f79e65e61754e8a611f8221d7c0cf36ee5af6f30aeff720924e64bb03d7f44c54fc31ae20926c354905f61df347830a7cba0c37afd41c1f59a25c52fa6f06  vector.confd
62db792de321655558bdb23ab9b3a7b35b84de445657011d88e8205cce4a926ff7b20f5304ec48fa646f1f259ad2136eceb5a377c4520071799da502eeff7592  logrotate
"
